package com.bw.area.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bw.area.mapper.TbDictionaryMapper;
import com.bw.area.service.TbDictionaryService;
import com.bw.po.TbDictionary;
import com.bw.result.ResponseState;
import com.bw.result.ResultVo;
import com.bw.vo.TbDictionaryVo;
import com.bw.vo.TbDictionaryVoVue;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 007
* @description 针对表【tb_dictionary(字典表)】的数据库操作Service实现
* @createDate 2023-11-12 19:03:48
*/
@Service
public class TbDictionaryServiceImpl extends ServiceImpl<TbDictionaryMapper, TbDictionary>
    implements TbDictionaryService {

    @Override
    public ResultVo listType(TbDictionaryVo tbDictionaryVo) {
        QueryWrapper<TbDictionary> wrapper = new QueryWrapper<>();
        //存储返回值
        ArrayList<TbDictionaryVo> dictionaryList = new ArrayList<>();
        //判断是标签还是房源类型
        wrapper.lambda().eq(TbDictionary::getType,tbDictionaryVo.getType());
        List<TbDictionary> list = list(wrapper);
        for (TbDictionary tbDictionary : list) {
            TbDictionaryVo dictionaryVo = new TbDictionaryVo();
            BeanUtils.copyProperties(tbDictionary,dictionaryVo);
            dictionaryList.add(dictionaryVo);
        }
        return ResultVo.SUCCESS(dictionaryList);
    }

    @Override
    public String getDictionaryID(TbDictionaryVo tbDictionaryVo) {
        QueryWrapper<TbDictionary> wrapper = new QueryWrapper<>();
        //根据id查询
        wrapper.lambda().eq(TbDictionary::getId,tbDictionaryVo.getId());
        TbDictionary tbDictionary = getOne(wrapper);
        TbDictionaryVo dictionaryVo = new TbDictionaryVo();
        BeanUtils.copyProperties(tbDictionary,dictionaryVo);
        return  dictionaryVo.getName();
    }

    @Override
    public List<String> getTags(ArrayList<String> split) {
        QueryWrapper<TbDictionary> wrapper = new QueryWrapper<>();
        //根据id查询
        wrapper.lambda().in(TbDictionary::getId,split);
        List<TbDictionary> list = list(wrapper);
        ArrayList<String> tags = new ArrayList<>();
        for (TbDictionary tbDictionary : list) {
            tags.add(tbDictionary.getName());
        }
        return tags;
    }

    @Override
    public ResultVo listTypeVue(TbDictionaryVo tbDictionaryVo) {

        QueryWrapper<TbDictionary> wrapper = new QueryWrapper<>();
        //存储返回值
        ArrayList<TbDictionaryVoVue> dictionaryList = new ArrayList<>();
        //判断是标签还是房源类型
        wrapper.lambda().eq(TbDictionary::getType,tbDictionaryVo.getType());
        List<TbDictionary> list = list(wrapper);
        for (TbDictionary tbDictionary : list) {
            TbDictionaryVoVue tbDictionaryVoVue = new TbDictionaryVoVue();
            tbDictionaryVoVue.setKey(tbDictionary.getId());
            tbDictionaryVoVue.setValue(tbDictionary.getName());
            tbDictionaryVoVue.setLabel(tbDictionary.getName());
            dictionaryList.add(tbDictionaryVoVue);
        }
        return ResultVo.SUCCESS(dictionaryList);
    }
}




